package MQTT

import (
	"fmt"
	mqtt "github.com/eclipse/paho.mqtt.golang"
)

var connectHandler mqtt.OnConnectHandler = func(client mqtt.Client) {
	fmt.Println("Connected")
}

var connectLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client, err error) {
	fmt.Printf("Connect lost: %v", err)
}

var OptMQTT *mqtt.ClientOptions

func InitMQTT() {
	var broker = "127.0.0.1"
	var port = 1883
	OptMQTT := mqtt.NewClientOptions()
	OptMQTT.AddBroker(fmt.Sprintf("mqtt://%s:%d", broker, port))
	OptMQTT.SetClientID("go_mqtt_client")
	OptMQTT.SetUsername("ziu")
	OptMQTT.SetPassword("zxcvbnm,./123")
	OptMQTT.OnConnect = connectHandler
	OptMQTT.OnConnectionLost = connectLostHandler
}
